package com.wxzhou.wangzhuan.constants;

/**
 * 登录事件对象
 */
public class LoginEvent {
    //设备ID
    private String deviceid;

    //登录成功后的用户ID，若有
    private Long userid;

    //ip地址
    private String ipAddress;

    //登录类型：0：设备登录，1：用户密码登录，2：其他
    private Integer loginType;

    //登录结果
    private boolean success;

    //失败原因
    private String failureReason;

    //登录时间
    private Long loginTime;

    private LoginEvent(String deviceid, Long userid, String ipAddress, Integer loginType, boolean success, String failureReason, Long loginTime) {
        this.deviceid = deviceid;
        this.userid = userid;
        this.ipAddress = ipAddress;
        this.loginType = loginType;
        this.success = success;
        this.failureReason = failureReason;
        this.loginTime = loginTime;
    }

    public static LoginEvent success(String deviceid, Long userid, String ipAddress, Integer loginType, Long loginTime) {
        return new LoginEvent(deviceid, userid, ipAddress, loginType, true, null, loginTime);
    }

    public static LoginEvent deviceSuccess(String deviceid, Long userid, String ipAddress, Long loginTime) {
        return new LoginEvent(deviceid, userid, ipAddress, 0, true, null, loginTime);
    }

    public static LoginEvent fail(String deviceid, String ipAddress, Integer loginType, String failureReason, Long loginTime) {
        return new LoginEvent(deviceid, null, ipAddress, loginType, false, failureReason, loginTime);
    }

    public static LoginEvent deviceFail(String deviceid, String ipAddress, String failureReason, Long loginTime) {
        return new LoginEvent(deviceid, null, ipAddress, 0, false, failureReason, loginTime);
    }

    public String getDeviceid() {
        return deviceid;
    }

    public Long getUserid() {
        return userid;
    }

    public String getIpAddress() {
        return ipAddress;
    }

    public Integer getLoginType() {
        return loginType;
    }

    public boolean isSuccess() {
        return success;
    }

    public String getFailureReason() {
        return failureReason;
    }

    public Long getLoginTime() {
        return loginTime;
    }
}
